home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # dhcp-end.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: dhcp-end.cgi,v 1.14 1997/06/24 22:20:56 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
-
- if (!$ARGV[0]) { printf("Location: %s%c%c","/tasks/Tasks.dhcp-start.cgi",10,10); }
-
- $myname = "dhcp-end.cgi?" . $ARGV[0];
- $def_config_dir = "/var/dhcp/config";
- $inetd_conf = "/etc/inetd.conf";
- $temp = "task.tmp";
- $dummy = "task.dummy";
-
- $it = "<td colspan=60>";
- $ni = "</td>";
- $bo = "<td colspan=150><font size=5><i>";
- $nb = "</i></font></td>";
-
- &get_fields;
-
- if ($fld{'cancel'}) {
- $message = "DHCP configuration cancelled";
- } elsif ($fld{'accept'}) {
- &configure;
- $done = 1;
- &generic;
- exit 0;
- } elsif ($fld{'left.x'}) {
- $go = "/tasks/Tasks.dhcp-start.cgi?e";
- print "Content-type: text/html\n\n";
- print "<HTML><HEAD>";
- print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$go\">";
- print "</HEAD><BODY></BODY></HTML>";
- exit 0;
- }
-
- &readValues;
-
- &generic;
-
- sub getLeases {
- undef @lst;
- opendir(CONFIG, $def_config_dir) ||
- &error("Unable to open directory $def_config_dir");
- while ($name = readdir(CONFIG) ) {
- if ($name =~ /^config\./) {
- $ipa = $name;
- $ipa =~ s/^config\.//;
- if ($ipa ne "Default") { push(@lst,$ipa); }
- }
- }
- closedir(CONFIG);
- }
-
- sub configure {
- &readValues;
-
- if ($terms{'status'} eq "Yes") {
- &getLeases;
-
- $oldFile = $def_config_dir . "/config.Default";
-
- @leases = split(/&&/,$terms{'leases'});
- foreach (@leases) {
- $newFile = $def_config_dir . "/config." . $_;
- if (-e $newFile) { next; }
- system("/sbin/cp", $oldFile, $newFile);
- }
-
- foreach $arg (@lst) {
- if (! grep(/$arg/,@leases)) {
- $newFile = $def_config_dir . "/config." . $arg;
- unlink $newFile;
- }
- }
- }
-
- system("/etc/chkconfig", "proclaim_server", "on");
- &inetd_comment($terms{'status'});
- }
-
- sub readValues {
- open(IN,"< $temp");
- while(<IN>) {
- @items = split(/=/);
- chop $items[1];
- $terms{$items[0]} = $items[1];
- }
- close(IN);
- }
-
- sub inetd_comment {
- if ($_[0] eq "Yes") {
- $comment = "/usr/etc/bootp";
- $uncomment = "/usr/etc/dhcp_bootp";
- $newLine = "bootp\tdgram\tudp\twait\troot\t/usr/etc/dhcp_bootp dhcp_bootp ";
- $newLine .= "-o /etc/config/dhcp_bootp.options\n";
- } else {
- $comment = "/usr/etc/dhcp_bootp";
- $uncomment = "/usr/etc/bootp";
- $newLine = "bootp\tdgram\tudp\twait\troot\t/usr/etc/bootp\tbootp\n";
- }
-
- $rename = 0;
- open(IN,"< $inetd_conf");
- open(OUT,"> $dummy");
- while(<IN>) {
- @items = split(/\s+/);
- if ($items[0] eq "bootp") {
- if ($items[5] eq $comment) {
- print OUT "# $_";
- $rename = 1;
- } else { print OUT $_; }
- } elsif ($items[0] eq "#bootp" || $items[1] eq "bootp") {
- if ($items[5] eq $uncomment || $items[6] eq $uncomment) {
- print OUT $newLine;
- $rename = 1;
- } else { print OUT $_; }
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- if ($rename) {
- rename($dummy, $inetd_conf);
- system("/etc/killall", "-HUP", "inetd");
- }
- }
-
- sub generic {
- print "Content-type: text/html\n\n";
- print "<html><head><title>Summary</title>\n";
- print "<script language=\"JavaScript\">\n<!--\n";
-
- # JavaScript
- print "which = \"none\";
- function runSubmit() {
- if(which == \"accept\") return (true);
- if(which == \"cancel\") return runCancel();
- return (true);
- }
- function markAccept() { which = \"accept\"; }
- function markCancel() { which = \"cancel\"; }
- function runCancel() {
- setTimeout('window.location=\"/tasks/Tasks.dhcp-start.cgi?end\"',0);
- return (false);
- }
- function Previous() {
- setTimeout('window.location=\"/tasks/Tasks.dhcp-start.cgi?end\"',0);
- return;
- }\n";
-
- print "//-->\n";
- print "</script></head>\n\n";
-
-
- print "<body bgcolor='ddc4b2' background=/tasks/dhcp-task.bg.gif>\n";
-
- print "<i>$message</i>";
-
- print "<table width=100%>",
- "<tr><th align=left><h1>Summary</h1></th>\n",
- "<th align=right><a href=\"/newsplash.shtml\">",
- "<img height=55 width=57 border=0 src=/tasks/home.gif></a>\n",
- " <a href=\"/tasks/Tasks.shtml\">",
- "<img height=55 width=57 border=0 src=/tasks/back.gif></a>",
- "</tr></table>\n";
-
- if ($done) {
- print qq|<center><br><br><br><br><font size=5>\n|;
- print qq|<i>Your DHCP server has been configured.</i>\n|;
- print qq|</font></center></body></html>\n|;
- return 0;
- }
-
- print "<br>
- Review the information that you entered in the DHCP configuration
- form:<br><br>\n\n";
-
- print "<center><table width=300>\n";
-
- print "<tr><td>Enable DCHP server: </td><td><tt>$terms{'status'}</tt></td></tr>\n";
- if ($terms{'status'} eq 'Yes') {
- print "<tr><td>Subnets served: </td><td><tt>";
- $terms{'leases'} =~ s/&&/<br>/g;
- print $terms{'leases'},"</tt></td></tr>";
- }
-
- print "</table></center><br>\n\n";
-
- printf("<form name=\"end\" action=\"%s\" method=post onSubmit=\"return runSubmit()\">\n", $myname);
-
- print "<center><table width=630><tr><td width=50%>",
- " If the information above is correct, select <I>Accept</I> to
- configure the Internet Gateway as a DHCP server.</td>";
-
- print "<td align=right><font size=5><i>\n";
- print qq|<input type=submit name="accept" value="Accept"
- onClick="markAccept()">\n|;
- print "</i></font></td></tr>\n\n";
-
- print "<tr><td>",
- " If you see an error in the information above, select <I>Cancel</I> to
- delay the configuration and return to the DHCP configuration form
- to correct your entries.</td>";
-
- print "<td align=right><font size=5><i>\n";
- print qq|<input type=submit name="cancel" value="Cancel"
- onClick="markCancel()">\n|;
- print "</i></font></td></tr></table></center><br>\n\n";
-
- print '<MAP NAME="js_map1">',
- ' <AREA SHAPE="rect" COORDS="0,0,59,52" HREF="javascript:Previous()">',
- '</MAP>',
- '<IMG SRC="/tasks/leftarrow.gif" BORDER=0 USEMAP="#js_map1" ALIGN="right">';
-
- print "\n</form></body></html>";
- }
-